aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/events/[...id].astro
blob: 4c9665e8378cd3014234d9e0092191db7572d5c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
---
import Breadcrumbs from '@/components/Breadcrumbs.astro'
import PostNavigation from '@/components/PostNavigation.astro'
import TOCHeader from '@/components/TOCHeader.astro'
import TOCSidebar from '@/components/TOCSidebar.astro'
import { badgeVariants } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import Layout from '@/layouts/Layout.astro'
import {
  getAdjacentEvents,
  getAllEvents,
  getTOCSections,
} from '@/lib/data-utils'
import { formatDate, iconMappings } from '@/lib/utils'
import { Icon } from 'astro-icon/components'
import { Image } from 'astro:assets'
import { render } from 'astro:content'

export async function getStaticPaths() {
  const events = await getAllEvents()
  return events.map((event) => ({
    params: { id: event.id },
    props: event,
  }))
}

const event = Astro.props
const currentEventId = Astro.params.id
const navigation = await getAdjacentEvents(currentEventId)
const { Content, headings } = await render(event)

const tocSections = await getTOCSections(currentEventId)
---

<Layout>
  {
    headings?.length > 0 &&
      !(headings.length === 1 && headings[0].text === event.data.title) && (
        <TOCHeader slot="table-of-contents" headings={headings} />
      )
  }

  <section
    class="grid grid-cols-[minmax(0px,1fr)_min(calc(var(--breakpoint-md)-2rem),100%)_minmax(0px,1fr)] gap-y-6"
  >
    <div class="col-start-2">
      <Breadcrumbs
        items={[
          { href: '/events', label: 'Events', icon: 'lucide:calendar-days' },

          {
            href: `/events/${currentEventId}`,
            label: event.data.title,
            icon: 'lucide:calendar-check',
          },
        ]}
      />
    </div>

    {
      event.data.image && (
        <Image
          src={event.data.image}
          alt={event.data.title}
          width={1200}
          height={630}
          class="col-span-full mx-auto w-full max-w-5xl object-cover"
        />
      )
    }

    <section class="col-start-2 flex flex-col gap-y-6 text-center">
      <div class="flex flex-col">
        <h1
          class="mb-2 scroll-mt-31 text-3xl leading-tight font-medium sm:text-4xl"
          id="event-title"
        >
          {event.data.title}
        </h1>

        <div
          class="text-muted-foreground divide-border mb-4 flex flex-col items-center justify-center divide-y text-xs sm:flex-row sm:flex-wrap sm:divide-x sm:divide-y-0 sm:text-sm"
        >
          <div
            class="flex w-full items-center justify-center gap-2 py-2 sm:w-fit sm:px-2 sm:py-0 first:sm:pl-0 last:sm:pr-0"
          >
            <span>{formatDate(event.data.date)}</span>
          </div>
        </div>
        <div class="flex flex-wrap justify-center gap-2">
          {
            event.data.type && (
              <a
                href={`/types/${event.data.type}`}
                class={badgeVariants({ variant: 'muted' })}
              >
                <Icon
                  name={iconMappings[event.data.type] || 'lucide:hash'}
                  class="size-3"
                />
                {event.data.type}
              </a>
            )
          }
        </div>
      </div>
    </section>

    {
      tocSections.length > 0 && (
        <TOCSidebar sections={tocSections} currentPostId={currentEventId} />
      )
    }

    <article class="prose col-start-2 max-w-none">
      <Content />
    </article>

    <PostNavigation
      newerPost={navigation.newer}
      olderPost={navigation.older}
      baseURL="/events/"
    />
  </section>

  <Button
    variant="outline"
    size="icon"
    className="group fixed right-8 bottom-8 z-50 hidden"
    id="scroll-to-top"
    title="Scroll to top"
    aria-label="Scroll to top"
  >
    <Icon
      name="lucide:arrow-up"
      class="mx-auto size-4 transition-all group-hover:-translate-y-0.5"
    />
  </Button>

  <script>
    document.addEventListener('astro:page-load', () => {
      const scrollToTopButton = document.getElementById('scroll-to-top')
      const footer = document.querySelector('footer')

      if (scrollToTopButton && footer) {
        scrollToTopButton.addEventListener('click', () => {
          window.scrollTo({ top: 0, behavior: 'smooth' })
        })

        window.addEventListener('scroll', () => {
          const footerRect = footer.getBoundingClientRect()
          const isFooterVisible = footerRect.top <= window.innerHeight

          scrollToTopButton.classList.toggle(
            'hidden',
            window.scrollY <= 300 || isFooterVisible,
          )
        })
      }
    })
  </script>
</Layout>

<script>
  const ensureKatexStyles = () => {
    if (!document.querySelector('.katex')) return
    if (document.querySelector('link[href*="katex.min.css"]')) return

    const link = document.createElement('link')
    link.rel = 'stylesheet'
    link.href = 'https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/katex.min.css'
    document.head.appendChild(link)
  }

  document.addEventListener('astro:page-load', ensureKatexStyles)
  document.addEventListener('astro:after-swap', ensureKatexStyles)
</script>